package com.jshan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jshan.base.entity.ServerMetrics;
import com.jshan.mapper.ServerMetricsMapper;
import com.jshan.service.ServerMetricsService;
import org.springframework.stereotype.Service;

@Service
public class ServerMetricsServiceImpl extends ServiceImpl<ServerMetricsMapper, ServerMetrics>
        implements ServerMetricsService {

    @Override
    public ServerMetrics getLatestMetrics(Long serverId) {
        LambdaQueryWrapper<ServerMetrics> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ServerMetrics::getServerId, serverId)
                .orderByDesc(ServerMetrics::getCreateTime)
                .last("LIMIT 1");
        return getOne(wrapper);
    }
}
